package com.da.lon.wang.xlg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.ResultSearchBean.ResultSearchListBean.SearchResultCategory.SearchResultCategoryItems;
import com.da.lon.wang.xlg.util.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class Classify3Adapter extends BaseAdapter {

    private Context context;
    private List<SearchResultCategoryItems> searchResultCategoryItems;
    private LayoutInflater inflater;

    public Classify3Adapter(List<SearchResultCategoryItems> list,
                            Context context) {
        // TODO Auto-generated constructor stub

        inflater = LayoutInflater.from(context);
        this.context = context;

        if (list == null) {
            searchResultCategoryItems = new ArrayList<SearchResultCategoryItems>();
        } else {
            this.searchResultCategoryItems = list;
        }

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return searchResultCategoryItems != null ? searchResultCategoryItems.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return searchResultCategoryItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        try {
            convertView = inflater.inflate(R.layout.ouka_classify3_item, null);

            TextView nameTextView = ViewHolder.get(convertView,
                    R.id.ouka_classify3_itname);
            SearchResultCategoryItems searchResultCategoryItem = searchResultCategoryItems
                    .get(position);
            nameTextView.setText(searchResultCategoryItem.getName());
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return convertView;
    }

}
